fix(backend): drop lockfile from prod image to clear false Trivy critical#1052
Merged
Conversation
…alse Trivy critical The Deploy Staging Trivy CRITICAL gate fails on a handlebars advisory. handlebars is a devDependency and the production stage installs prod-only deps (npm ci --omit=dev), so it is never actually present in the image. The failure comes from package-lock.json: it is copied in for npm ci and then left behind, and Trivy reads the lockfile's full dependency tree — including devDependencies — and reports their advisories against the image. Remove the lockfile after install. It is a build-time artifact with no runtime purpose, and dropping it makes the scan reflect what is actually installed (production dependencies only). The remaining axios advisories are HIGH, which the warn-only step reports without failing the build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
With the Trivy image-ref now fixed (#1050), the Deploy Staging CRITICAL gate runs and fails on a
handlebarsadvisory. Buthandlebarsis a devDependency — the production stage installs prod-only deps (npm ci --omit=dev), so it is never actually in the image.The failure comes from
package-lock.json: it is copied in fornpm ciand then left in the image. Trivy reads the lockfile's full dependency tree (including devDependencies) and reports their advisories against the image, even though those packages aren't installed.Fix
Remove the lockfile after install:
RUN npm ci --omit=dev && rm -f package-lock.jsonIt's a build-time artifact with no runtime purpose. Dropping it makes the scan reflect what's actually installed (production deps only). The remaining
axiosadvisories are HIGH, which the warn-only Trivy step reports without failing the build.Verification
Deploy Staging only runs on push to
main, so it can't run on this PR — it'll execute on the post-merge run. Change is limited to the backend production Docker stage; it does not affect the PR-gating RemitLend CI job or the app at runtime.